<template>
  <div class="container">
    <div class="navbar">
      <van-image
        fit="cover"
        round
        width="60px"
        height="60px"
        :src="userInfo.photo"
      />
      <p class="name">
        {{ userInfo.name }}
        <br />
        <van-tag type="primary" color="white" text-color="#0098fa"
          >{{ userInfo.birthday }}
        </van-tag>
      </p>
    </div>
    <van-row>
      <van-col span="8"
        ><van-icon name="newspaper-o" color="red" />
        <br />
        我的作品</van-col
      >
      <van-col span="8">
        <van-icon name="star-o" color="yellow" />
        <br />
        我的收藏</van-col
      >
      <van-col span="8">
        <van-icon name="todo-list-o" color="green" />
        <br />
        阅读历史</van-col
      >
    </van-row>
    <van-cell-group route>
      <van-cell
        title="编辑资料"
        icon="edit"
        to="/edit"
        @click="pushInfo"
        is-link
      />
      <van-cell title="小智同学" icon="chat-o" is-link />
      <van-cell title="系统设置" icon="setting-o" is-link />
      <van-cell title="退出登录" icon="warning-o" is-link @click="loginOut" />
    </van-cell-group>
  </div>
</template>

<script>
import { removeToken } from '../../utils/token.js'
import { getUserInfo } from './user.js'
export default {
  name: 'user',
  data () {
    return {
      userInfo: {}
    }
  },
  created () {
    getUserInfo().then(res => {
      console.log(res)
      this.userInfo = res.data.data
    })
  },
  methods: {
    loginOut () {
      this.$dialog
        .confirm({ title: '温馨提示', message: '确定退出?' })
        .then(() => {
          removeToken()
          this.$router.push({ name: 'home' })
        })
        .catch(err => {})
    },
    pushInfo () {
      this.$router.push({
        name: 'edit'
      })
    }
  }
}
</script>

<style lang="less" scoped>
.container {
  .navbar {
    display: flex;
    justify-content: start;
    align-items: center;
    background-color: #0098fa;
    .van-image {
      margin: 15px;
    }
    .name {
      font-size: 14px;
      color: white;
    }
  }
  .van-col {
    font-size: 14px;
    text-align: center;
    margin: 20px 0;
    .van-icon {
      font-size: 24px;
    }
  }
}
</style>
